/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managertelaCadastros;

import classes.TipoServico;
import dao.DaoTipoServico;
import java.util.List;
import telaCadastros.CadTipoServico;
import util.Mensagem;

/**
 *
 * @author fumio
 */
public class managerCadTipoServico implements interfaceManager {

    private TipoServico tipoServico;
    private CadTipoServico cadTipoServico;
    private DaoTipoServico daoTipoServico;

    public managerCadTipoServico(TipoServico cTipoServico) {
        cadTipoServico = CadTipoServico.getInstance(this);
        daoTipoServico = new DaoTipoServico();
        if (cTipoServico == null) {
            tipoServico = new TipoServico();
        } else {
            tipoServico = cTipoServico;
        }
        cadTipoServico.setVisible(true);
    }

    @Override
    public boolean salvar() {
        if (Mensagem.confirmarCadastro("filial")) {
            try {
                if (tipoServico == null) {
                    tipoServico = new TipoServico();
                }
                if (setData()) {
                    daoTipoServico.salvar(tipoServico);

                }

                return true;

            } catch (Exception e) {
                System.out.println(e.getMessage());
                return false;
            }

        } else {
            return false;
        }


    }

    @Override
    public List carregar() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean setData() {
        boolean response;
        try {
            tipoServico.setDescricao(cadTipoServico.edtTipoServico.getText());
            response = true;
        } catch (Exception e) {
            response = false;
        }
        return response;
    }

    @Override
    public void getData() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
